package com.hawthorn.claim.controller;

import com.hawthorn.component.ret.RestResult;
import com.hawthorn.platform.context.ContextHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

/**
 * @copyright: Copyright (c) 2020 andyten
 * <p></p>
 * @remark: hello测试
 * @author:andyten@tom.com | xukaixing@hotmail.com
 * @date:2020/10/28 4:01 下午
 * @version v1.0.1
 */
@Api(tags = {"claim-hello"})
@RestController
@RequestMapping("/claimhello")
@Slf4j
public class HelloController
{
  /**
   * @author: andyten@tom.com | xukaixing@hotmail.com
   * @date: 2020/10/28 4:04 下午
   * @version: 1.0.1
   */
  @ApiOperation(value = "hello->sayHello", notes = "")
  @ApiImplicitParams({
  })
  @GetMapping(value = "/sayClaimHello")
  public RestResult sayClaimHello()
  {
    // HystrixConcurrencyContext rqObj = HystrixConcurrencyContextHolder.getContext();
    // Object obj = rqObj.get(HttpServletRequest.class.getName());
    // if (obj == null)
    //   log.info("eeeee");
    // else log.info((((HttpServletRequest) obj).getHeader("useraccount")));
    ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = attributes.getRequest();
    // request header中设置useraccount，则以下输出都是header中内容，做到了feign接口不同的线程传递header
    log.info("====>>>>" + request.getHeader("useraccount"));
    log.info("====>>>>" + ContextHolder.getUserAccount());
    // getParameter获取不到参数，因为FeignConfig的apply方法中只设置了header参数
    log.info("====>>>" + request.getParameter("test"));
    log.info("====== feign 执行 ======");
    return RestResult.success("hello claim ! ");
  }
}
